package cn.zqy;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import javax.servlet.http.*;

import cn.zqy.model.Library;
import cn.zqy.services.LibraryService;

@SuppressWarnings("serial")
public class MphalibServlet extends HttpServlet
{
	public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException
	{
		
		localImport();
	}

	private void localImport() throws FileNotFoundException, IOException
	{
		File file=new File("WEB-INF/BookList.txt");
		BufferedReader reader=new BufferedReader(new FileReader(file));
		String line=reader.readLine();
		while(line!=null)
		{
			//res.getWriter().println(line);
			String[] elements=line.split("@");
			Library library=new Library();
			library.setBookNo(elements[0].trim());
			library.setBookName(elements[1].trim());
			library.setLanguage(elements[2].trim());
			library.setBookOwner(elements[3].trim());
			library.setBookStatus(elements[4].trim());
			new LibraryService().persistent(library);
			line=reader.readLine();
		}
	}
}
